package com.yiwu.web.service.impl;

import com.yiwu.common.enums.ResponseCode;
import com.yiwu.common.exception.BusinessException;
import com.yiwu.common.utils.MinioUtil;
import com.yiwu.common.model.vo.file.UploadFileRspVO;
import com.yiwu.web.service.FileService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

/**
 * @version 1.0
 * @description TODO
 * @date 2024/5/21 18:59
 */
@Service
@Slf4j
public class FileServiceImpl implements FileService {

    @Resource
    private MinioUtil minioUtil;

    @Override
    public UploadFileRspVO uploadFile(MultipartFile file) {
        try {
            String url = minioUtil.uploadFile(file,"alsfhkjghxx");
            return UploadFileRspVO.builder().url(url).build();
        } catch (Exception e) {
            log.error("==> 上传文件至 Minio 错误: ", e);
            throw new BusinessException(ResponseCode.UPLOAD_ERROR);
        }
    }

    @Override
    public UploadFileRspVO sendImage(MultipartFile file) {
        try {
            String url = minioUtil.uploadFile(file,"aslkkjhzz");
            return UploadFileRspVO.builder().url(url).build();
        } catch (Exception e) {
            log.error("==> 上传文件至 Minio 错误: ", e);
            throw new BusinessException(ResponseCode.UPLOAD_ERROR);
        }
    }
}
